<?php get_header(); ?>
    
    <div id="main">
    	<div class="wrapper">
            <div class="maincontent">
                <img src="<?php bloginfo('template_url'); ?>/images/under-construction.jpg" alt="Under construction" />
                <div class="breadcrumb">
                    <?php 
                        if(function_exists('bcn_display')){
                            bcn_display();
                        }
                    ?>
                </div>
                <h1><?php single_post_title('', true) ?></h1>
                <div class="contact-info">
                    <?php
                        $content_post = get_post($post->ID);
                        $content = $content_post->post_content;
                        $content = apply_filters('the_content', $content);
                        $content = str_replace(']]>', ']]>', $content);
                        echo $content;
                        
                        $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc','exclude' => 239) );
                    ?>
                    <ul class="map-tabs">
                        <?php 
                            $i=0;
                            foreach($mypages as $page){ $i++;
                                if($i==1) $cl ='first';elseif($i==2) $cl=''; elseif($i==3) $cl ='last';
                                echo'<li class="'.$cl.'"><a href="#tab'.$i.'" id="showMap'.$i.'">'.$page->post_title.'</a></li>';
                            }
                        ?>
                    </ul>
                    <div class="map-tab-container">
                        <?php 
                            $i=0;
                            foreach($mypages as $page){ $i++;
                                if(get_post_meta($page->ID, 'location')){
                                    $location = get_post_meta($page->ID, 'location');
                                    $locations = explode(',',$location[0]);
                                }
                                if(get_post_meta($page->ID, 'title')){
                                    $title = get_post_meta($page->ID, 'title');
                                }
                                if(get_post_meta($page->ID, 'address')){
                                    $address = get_post_meta($page->ID, 'address');
                                }
                        ?>
                        <div id="tab<?php echo $i; ?>" class="map-tab-content">    
                            <div class="info">
                                <?php 
                                    $content = $page->post_content;
                                    if ( ! $content ) // Check for empty page
                                        continue;
                                    $content = apply_filters( 'the_content', $content );
                                    echo $content;
                                ?>
                            </div>
                            <div class="map">
                            	<script type="text/javascript" language="javascript">
                                    //<![CDATA[
                                    $(document).ready(function() {
                                    
                                      function initialize() {
                                        var myLatlng = new google.maps.LatLng(<?php echo (count($locations)>1)?$locations[0].','.$locations[1]:'' ?>);
                                        var myOptions = {
                                          zoom: 14,
                                          center: myLatlng,
                                          mapTypeId: google.maps.MapTypeId.ROADMAP
                                        }
                                        
                                        var map = new google.maps.Map(document.getElementById("map_canvas<?php echo $i; ?>"), myOptions);
                                        
                                        var contentString = '<div id="content">'+
                                            '<h2><?php if(isset($title)) echo $title[0]; ?></h2>'+
                                            '<div>'+
                                            '<p><?php if(isset($address)) echo $address[0]; ?></p>'+
                                            '</div>'+
                                            '</div>';
                                    
                                        var infowindow = new google.maps.InfoWindow({
                                            content: contentString,
                                            maxWidth: 300
                                        });
                                    
                                        var marker = new google.maps.Marker({
                                            position: myLatlng,
                                            map: map,
                                            title: '<?php if(isset($title)) echo $title[0]; ?>'
                                        });
                                        google.maps.event.addListener(marker, 'click', function() {
                                          infowindow.open(map,marker);
                                        });
                                    
                                      }
                                            $("#tab<?php echo $i; ?>").css({'display':'block'});
                                            $("#map_canvas<?php echo $i; ?>").css({'width':'400px', 'height':'300px'});
                                            initialize();
                                        // Function added to help reset map and container boundaries
                                        $("#showMap<?php echo $i; ?>").click(function() {
                                                $("#tab<?php echo $i; ?>").css({'display':'block'});
                                                $("#map_canvas<?php echo $i; ?>").css({'width':'400px', 'height':'300px'});
                                                initialize();
                                                //alert('showMap Clicked!');
                                        });
                                        
                                     initialize(); 
                                
                                    });
                                    //]]>
                                    </script>
                                    <div id="map_canvas<?php echo $i; ?>"></div>
                            </div>
                        </div>
                        <?php }?>
                	</div>
                
                    <?php
                        $my_id = 239;
                        $content_post = get_post($my_id);
                        $content = $content_post->post_content;
                        $content = apply_filters('the_content', $content);
                        $content = str_replace(']]>', ']]>', $content);
                        echo $content;
                    ?>
            	</div>
            </div><!-- //maincontent -->
            <div class="aside">
                <p class="title"><strong>Contact Us</strong></p>
            </div>
            <div class="clr"></div>
            <div class="bg-main-bot"></div>
        </div><!-- //aside -->
    </div><!-- //main -->
<?php get_footer(); ?>